home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / debugger / ddd-1.000 / ddd-1 / ddd-1.4b / etc / shorten.c < prev   
Encoding:
C/C++ Source or Header  |  1995-05-01  |  2.3 KB  |  102 lines

  1. /* $Id: shorten.c,v 1.1.1.1 1995/05/01 15:48:43 zeller Exp $ */
  2. /* Convert long filenames to short ones, according to OSF/Motif convention */
  3.  
  4. /*
  5.     Copyright (C) 1993 Technische Universitaet Braunschweig, Germany.
  6.     Written by Andreas Zeller (zeller@ips.cs.tu-bs.de).
  7.  
  8.     This file is part of NORA.
  9.  
  10.     NORA is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2 of the License, or (at your option) any later version.
  14.  
  15.     NORA is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18.     See the GNU General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU General Public
  21.     License along with NORA -- see the file COPYING.
  22.     If not, write to the Free Software Foundation, Inc.,
  23.     675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     NORA is an experimental inference-based software development
  26.     environment. Contact nora@ips.cs.tu-bs.de for details.
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include <string.h>
  32. #include <stdlib.h>
  33.  
  34. extern int puts();
  35.  
  36. static char *shorten(s, length)
  37.     char *s;
  38.     int length;
  39. {
  40.     static char ret[BUFSIZ];
  41.  
  42.     char abbrev[BUFSIZ + 1];
  43.     char trailer[BUFSIZ];
  44.  
  45.     int i, j;
  46.     int a = 0;
  47.     int t = 0;
  48.  
  49.     /* if length is enough, return */
  50.     if (strlen(s) <= length)
  51.     return s;
  52.  
  53.     /* find trailer */
  54.     for (i = 0; s[i] != '.' && s[i] != '\0'; i++)
  55.     ;
  56.  
  57.     /* fetch trailer */
  58.     strcpy(trailer, s + i);
  59.     t = strlen(trailer);
  60.  
  61.     a = 0;
  62.     abbrev[BUFSIZ] = '\0';
  63.  
  64.     /* fetch abbrev */
  65.     for (; i > 0 && i + a + t >= length; i--)
  66.     if (isupper(s[i]))
  67.         abbrev[BUFSIZ - ++a] = s[i];
  68.  
  69.     /* cut after upper-case-letter, if it's not the first */
  70.     for (j = i; j > 0 && !isupper(s[j]); j--)
  71.     ;
  72.     if (j > 0)
  73.     i = j;
  74.  
  75.     /* echo it all */
  76.     s[i + 1] = '\0';
  77.     strcpy(ret, s);
  78.     strcat(ret, abbrev + BUFSIZ - a);
  79.     ret[length - t] = '\0';
  80.     strcat(ret, trailer);
  81.     ret[length] = '\0';
  82.  
  83.     return ret;
  84. }
  85.  
  86.  
  87. int main(argc, argv)
  88.     int argc;
  89.     char *argv[];
  90. {
  91.     char s[BUFSIZ];
  92.     int length = 12; /* system V convention */
  93.  
  94.     if (argc > 1)
  95.     length = atoi(argv[1]);
  96.  
  97.     while (gets(s) != NULL)
  98.     puts(shorten(s, length));
  99.  
  100.     return 0;
  101. }
  102.